<template>
<div>
  <el-dialog :title="$t('DEVICE.ADDEVICES')" :close-on-click-modal="false"  :visible.sync="show"
   class="my_devices_dialog my_devices_dialog_bind pcShow" :before-close="close" v-if="!isPhone">
    <div class="my_devices_bind" v-for="item in data" :key="item.mm">
      <el-image :src="item.product_image"></el-image>
      <div class="my_devices_item_content">
        <p  class="my_devices_bind_title">{{item.product_title}}</p>
        <p class="my_devices_bind_sectitle">{{$t('DEVICE.ORDERID')}}:{{item.order_no}}</p>
        <!-- <p class="my_devices_bind_sectitle">{{item.first_type}}</p> -->
        <span class="first_type">{{item.first_type}}</span>
      </div>

    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="cancle">{{$t('CONTACTUS.BACK')}}</el-button>
      <el-button type="search" :loading="loading" @click="submitForm">{{$t('CONTACTUS.SUBMIT')}}</el-button>
    </span>
  </el-dialog>
  <el-dialog  :close-on-click-modal="false"  :visible.sync="show" :show-close="false"
   class="my_devices_dialog my_devices_dialog_bind phoneShow" :before-close="close" v-if="isPhone">
    <p class="my_devices_header" slot="title">
      <span class="back" @click="cancle">Back</span>
      <span class="my_devices_header_title">{{$t('DEVICE.ADDEVICES')}}</span>
      <span class="blue" @click="submitForm">Bind</span>
    </p>
    <div class="my_devices_bind" v-for="item in data" :key="item.mm">
      <el-image :src="item.product_image"></el-image>
      <div class="my_devices_item_content">
        <p  class="my_devices_bind_title">{{item.product_title}}</p>
        <p class="my_devices_bind_sectitle">{{$t('DEVICE.ORDERID')}}:{{item.order_no}}</p>
        <!-- <p class="my_devices_bind_sectitle">{{item.first_type}}</p> -->
        <span class="first_type">{{item.first_type}}</span>
      </div>

    </div>
  </el-dialog>
</div>

 
</template>

<script>
// import { productBasicDel } from '@/api/product/productBasic.js'
import { add } from '@/api/personalCenter/devices.js'
import { mapGetters } from 'vuex'

export default {
  data () {
    return {
      data: [],
      loading: false
    }
  },
  props: {
    show: Boolean,
    closeDialog:Function,
  },
  computed: {
    ...mapGetters(['isPhone']),
  },
  watch: {
    show:  function() {
      if(this.show) {
        this.data = this.$parent.deviceSearchList
      }
    }
  },
  methods: {
    close () {
      this.$emit('closeDialog', 2)
    },
    cancle() {
      this.$emit('closeDialog')
    },
    submitForm(){
      this.add()
    },
    add() {
      this.loading = true
      let params = {
        order_no: this.data[0].order_no
      }
      add(params).then( () => {
        this.$emit('closeDialog', 1)
        this.loading = false
      })
    }
  }
}
</script>

<style>

</style>